﻿using SqlAnalysis;
using System.Text;

namespace ConsoleTest
{
    class Program
    {
        static Program() 
        {
            new SqlParser();
        }

        static void Main(string[] args)
        {
            // UNION | UNION  ALL 要单独处理 （分组在合并 结果集）
            var xxx = " xx in asd ".Trim();
            ;
            string sql = "select * from student m join  Test n  on m.id=n.id where (m.id>0 or m.id>1) and m.id< 10";
            sql = "select x from (select * from (select * from (select 1 as x from ordertable) as #xxx where (x=1 or x = 2) and x>2 or (x=1 or x = '23') or (x=1 or x = '234') or (x=1 or x = '23')) as #xxx) as asd";
            sql = "select top 100 t1.name, t1.code, t2.age, t2.address, school as xx from person t1 left join person_info as t2 on t1.id = t2.id and t1.code > t2.age and t1.name = '12321'";

            sql = @"select ob.order_status,ob.price,op.content,op.user_key,od.content from order_basis ob 
inner join (select * from order_pay) as op on op.order_key = ob.order_key and  ob.order_key > 20
left join  order_address as od on od.order_key = op.order_key and od.order_key = op.order_key and ob.payment > 0";

            //sql = "select * from student m join  Test n  on m.id=n.id where (m.id>0 or m.id>1) and m.id< 10 or column_name BETWEEN SX.valuel AND SQ.value2";

            sql = @"select distinct top 100 ob.*   ,   *,ob.order_status as xx,ob.price x2, op.content,op.user_key,od.content from order_basis ob
            inner join(select* from order_pay) as op on(op.order_key = ob.order_key or ob.order_key < 1) and ob.order_key > 26 or ob.order_key > 999
            left join order_address as od on od.order_key = op.order_key and od.order_key = op.order_key and ob.payment > O
              where op.user_key > 10 and od.content in (1, 2, 3) or ob.price <> 2 and od.content like 'ads%' and column_name BETWEEN SX.valuel AND SQ.value2
            order by op.user_key , od.content desc
            group by op.user_key ,od.content
            having SUM(op.user_key) > AVG(26)";

            sql = @"SELECT country as qwe,sum(age), name ret,year%age as iok, CASE SCORE WHEN 'A' THEN '优' ELSE '不及格' END as xx FROM Websites
                    WHERE country='CN'
                    UNION ALL
                    SELECT country, app_name FROM apps
                    WHERE country='CN'
                    ORDER BY country";

            TimeSpan start = new TimeSpan(DateTime.Now.Ticks);  //获取当前时间的刻度数

            //{
            //    SqlParser analysisTSQL = new SqlParser();
            //    analysisTSQL.Convert(sql);
            //}

            {
                new SqliteTest().InsertMultipleWithTransaction(10000);
            }

            if (false)
            {
                Parallel.For(0, 1_00_000, new ParallelOptions
                {
                    MaxDegreeOfParallelism = 8
                }, i =>
                {
                    SqlParser analysisTSQL = new SqlParser();
                    analysisTSQL.Convert(sql);
                });
            }

            TimeSpan end = new TimeSpan(DateTime.Now.Ticks);    //获取当前时间的刻度数
            TimeSpan abs = end.Subtract(start).Duration();      //时间差的绝对值
            Console.WriteLine(string.Format("程序执行时间：{0},{1}", abs.TotalMilliseconds, 1_00_000 / abs.TotalMilliseconds));

            Console.ReadKey();
        }
    }
}
